package com.kfm.base.array2;

public class Demo12 {

    public static void main(String[] args) {
        /*
          交集
         */
        int[] arr1 = {4, 2, 3};
        int[] arr = {1, 2, 3};

        // Math.min(arr.length, arr1.length);
        int[] result = new int[arr1.length > arr.length? arr.length: arr1.length];

        int index = 0;
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if (arr1[i] == arr[j]){
                    result[index ++] = arr[j];
                    break;
                }
            }
        }

        for (int i = 0; i < index; i++) {
            System.out.println(result[i]);
        }

    }
}
